import 'package:flutter/material.dart';

/// 透明度控制演示页面
class OpacityDemo extends StatefulWidget {
  const OpacityDemo({Key? key}) : super(key: key);

  @override
  _OpacityDemoState createState() => _OpacityDemoState();
}

class _OpacityDemoState extends State<OpacityDemo> {
  double _opacity = 1.0;

  void _toggleOpacity() {
    setState(() {
      _opacity = _opacity == 1.0 ? 0.3 : 1.0;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("整体透明度控制")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Opacity(
              opacity: _opacity,
              child: Column(
                children: [
                  Text(
                    "这是一个文本控件",
                    style: TextStyle(fontSize: 24),
                  ),
                  SizedBox(height: 10),
                  Icon(Icons.star, size: 50, color: Colors.orange),
                  SizedBox(height: 10),
                  Container(
                    width: 100,
                    height: 100,
                    color: Colors.blue,
                  ),
                ],
              ),
            ),
            SizedBox(height: 40),
            ElevatedButton(
              onPressed: _toggleOpacity,
              child: Text("切换透明度"),
            )
          ],
        ),
      ),
    );
  }
}